#pragma once

#include "../Math/Vec2i.h"
#include <libtcod/libtcod.hpp>
#include <memory>
#include <vector>

typedef std::shared_ptr<TCODNoise> TCODNoisePtr;
typedef std::shared_ptr<TCODRandom> TCODRandomPtr;

class Grid;
typedef std::shared_ptr<Grid> GridPtr;

class Chunk;
typedef std::shared_ptr<Chunk> ChunkPtr;

class World
{
public:
	World();
	~World();

	void init(const Vec2i &viewport);
	void update();
	void render();

	const GridPtr &getGrid() const { return grid; }

private:
	Vec2i chunk_size;

	GridPtr grid;

	TCODNoisePtr noise;
	TCODRandomPtr ran;
	Vec2i next_center_pos;

	void generateChunk(ChunkPtr &chunk, const Vec2i &pos);
	void updatePlayerOnCenter(const Vec2i direction_data, bool walking_west, bool walking_north);
	bool findNextCenter(const Vec2i direction_data, bool walking_west, bool walking_north);
	void checkCacheThreshold(const Vec2i direction_data, bool walking_west, bool walking_north);
	void loadChunk(const Vec2i &pos);
};
typedef std::shared_ptr<World> WorldPtr;
